package com.qf.fmall.controller;

import com.qf.fmall.entity.Orders;
import com.qf.fmall.entity.ShoppingCart;
import com.qf.fmall.service.ShoppingCartService;
import com.qf.fmall.utils.Base64Utils;
import com.qf.fmall.vo.ResStatus;
import com.qf.fmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/shopcart")
public class ShopCartController {

    @Autowired
    private ShoppingCartService cartService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @CrossOrigin
    public ResultVo addCartTo(@RequestBody ShoppingCart cart) {
        /*
            对于token的要求有哪些？
                1，token只能被服务器端进行解码
         *      2，如何在token中保留登录的时间
         * */
        //处理购物车的业务逻辑
        ResultVo resultVo = cartService.addCartTo(cart);
        return resultVo;
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    public ResultVo searchCart(Integer userId) {
        ResultVo resultVo = cartService.listByUserId(userId);
        return resultVo;
    }

    @RequestMapping(value = "/update/{cid}/{cnum}", method = RequestMethod.PUT)
    @CrossOrigin
    public ResultVo updateCart(@PathVariable("cid") Integer cid, @PathVariable("cnum") Integer cnum) {
        ResultVo resultVo = cartService.updateCart(cid, cnum);
        return resultVo;
    }

    @RequestMapping(value = "/listbycids", method = RequestMethod.GET)
    @CrossOrigin
    public ResultVo listByCids(String cids) {
        ResultVo resultVo = cartService.listByCids(cids);
        return resultVo;
    }

}
